	function CourseView() {
		this.objComm = null;
		this.objCourse = null;
		this.objCourseViewReply = null;
		
		this.board_seq = null;
		this.rtn_addr = null;
	};
	
	CourseView.prototype = {
			onPageShow: function() {
				this._init();
			}
			, getParam: function(){
				if(!_gf.COURSE_DATA) _gf.COURSE_DATA = "";
				
				this.board_seq = _util.nvl(_gf.COURSE_DATA["키"]);
				this.rtn_addr = _util.nvl(_gf.COURSE_DATA["리턴주소"]);
				
			}
			, setParam: function(){
				if(!_gf.COURSE_DATA) _gf.COURSE_DATA = "";
			}
			, _init: function(){
				
				$("a").attr("href","");
				
				this.objComm = new CourseView_Comm();
				this.objCourse = new clsCourseView();
		    this.objCourseViewReply = new clsCourseViewReply();
		     	
		    this.getParam();
		    
		    //프로필정보 조회
		    this.spinStart();
		    this.objComm.setCourseRequest("나이스샷", _util.nvl(_gf.COURSE_DATA["나이스샷수"]));
		    this.objComm.setCourseRequest("게시판키", this.board_seq);
		    this.objComm.getCourseTarget();
		    
		    this.objCourse.$getViewLayer().find("li.bt_my div.ui-block-a").hide();
		    
		    this.objComm.getReplyList();
		    
		    this._bind();
		      
			}
			, _bind: function(){
				var thisClass = this;
				
				//코스상세 조회 완료이벤트
				$(this.objComm).bind("evtFinishCourseView", function(event){
					var thisData = thisClass.objComm.getCourseTargetData();
					thisClass.objCourse.setUserId(thisClass.objComm.getCourseRequest("아이디"));
					thisClass.objCourse.setDetail(thisData);
				});
				
				//덧글리스트 조회 완료이벤트
				$(this.objComm).bind("evtFinishReplyList", function(event){
					var thisData = thisClass.objComm.getCourseReplyList();
					thisClass.objCourseViewReply.setUserId(thisClass.objComm.getCourseRequest("아이디"));
					thisClass.objCourseViewReply.setList(thisData);
					thisClass.spinEnd();
				});
				
				//댓글삭제 완료 이벤트
				$(this.objComm).bind("evtFinishDeleteCourseView", function(event, resData){
					alert(resData["메세지"]);
					if(resData["응답코드"]){
						$.mobile.changePage("course.html","slide",true);
					}
				});
				
				//댓글등록 완료 이벤트
				$(this.objComm).bind("evtFinishInsertCourseReply", function(event, resData){
					alert(resData["메세지"]);
					thisClass.objComm.getReplyList();
				});
				
				//나이스샷 추가완료 이벤트
				$(this.objComm).bind("evtFinishUpdateNiceShot", function(event, resData){
					alert(resData["메세지"]);
					thisClass.objComm.getCourseTarget();
				});
				
				//댓글동륵 이벤트
				this.objCourseViewReply.$replyRegist().find("div.ui-block-b a").click(function(event){
					if(!thisClass._role()) return;
					var content = thisClass.objCourseViewReply.$replyRegist().find("div.ui-block-a textarea").val();
					if(content){
						thisClass.spinStart();
						thisClass.objComm.setCourseRequest("댓글내용", content);
						thisClass.objComm.registReply();
						thisClass.objCourseViewReply.$replyRegist().find("div.ui-block-a textarea").val("");
					}else{
						alert("댓글을 입력하세요.");
					}
				});
				
				//댓글삭제 이벤트
				this.objCourseViewReply.$getReplyLayer().on("click", "li span.ico_navi", function(event){
					if(!thisClass._role()) return;
					var idx = thisClass.objCourseViewReply.$getReplyLayer().find("li span.ico_navi").index($(this));
					var seq = thisClass.objCourseViewReply.listData[idx]["키"];
					if(seq){
						thisClass.spinStart();
						thisClass.objComm.setCourseRequest("댓글키", seq);
						thisClass.objComm.deleteReply();
					}
				});
				
				//댓글 프로필 이벤트
				this.objCourseViewReply.$getReplyLayer().on("click", "li img", function(event){
					var idx = thisClass.objCourseViewReply.$getReplyLayer().find("li img").index($(this));
					_gf.PROFILE_DATA["userId"] = thisClass.objCourseViewReply.listData[idx]["등록자"];
					$.mobile.changePage("../mypage/profile_view.html", "slide", true);
				});
				
				//게시글 삭제 이벤트
				this.objCourse.$getViewLayer().find("li:eq(1) a").click(function(event){
					if(!thisClass._role()) return;
					thisClass.objComm.deleteCourse();
				});
				
				//게시글 수정 이벤트
				this.objCourse.$getViewLayer().find("li.bt_my div.ui-block-a").on("click", function(event){
					alert("수정");
				});
				
				//프로필 이미지 크게보기
				this.objCourse.$getViewLayer().find("li:eq(2) span a").click(function(){
					var thisData = thisClass.objComm.getCourseTargetData();
					if(!_gf.COURSE_DATA) _gf.COURSE_DATA = "";
					_gf.COURSE_DATA = {
						"이미지" : _util.nvl(thisData["이미지"]).replace('/data/msp300/dl/files/free', 'http://192.168.0.82')
						, "URL": "../course"
						, "키" : thisClass.board_seq
					}
					$.mobile.changePage("../inc/img_view.html","slide",true);
				});
				
				//나이스샷 이벤트
				this.objCourse.$getViewLayer().find("li.bt_side>div div:eq(0) a:eq(0)").click(function(){
					if(!thisClass._role()) return;
					thisClass.objComm.setCourseRequest("댓글키", null);
					thisClass.objComm.registNiceShot("view");
				});
				
				//댓글 나이스샷 이벤트
				this.objCourseViewReply.$getReplyLayer().on("click", "li p a", function(event){
					if(!thisClass._role()) return;
					var idx = thisClass.objCourseViewReply.$getReplyLayer().find("li p a").index($(this));
					thisClass.objComm.setCourseRequest("댓글키", thisClass.objCourseViewReply.listData[idx]["키"]);
					thisClass.objComm.registNiceShot("list");
				});
				
				//나이스샷 리스트 이벤트
				this.objCourse.$getViewLayer().find("li.bt_side>div div:eq(0) a:eq(1)").click(function(){
					if(!_gf.COURSE_DATA) _gf.COURSE_DATA = "";
					_gf.COURSE_DATA = {
						"게시판키" : _util.nvl(thisClass.objComm.getCourseRequest("게시판키"))
						, "키" : thisClass.board_seq
					}
					
					$.mobile.changePage("nice_shot.html","slide",true);
				});
				
				//댓글 나이스샷 리스트 이벤트
				this.objCourseViewReply.$getReplyLayer().on("click", "li p mark", function(event){
					var idx = thisClass.objCourseViewReply.$getReplyLayer().find("li p mark").index($(this));
					if(!_gf.COURSE_DATA) _gf.COURSE_DATA = "";
					_gf.COURSE_DATA = {
						"게시판키" : _util.nvl(thisClass.objCourseViewReply.listData[idx]["게시판키"])
						, "댓글키": _util.nvl(thisClass.objCourseViewReply.listData[idx]["키"])
						, "키" : thisClass.board_seq
					}
					//alert(thisClass.objCourseViewReply.listData[idx]["게시판키"]);
					//alert(thisClass.objCourseViewReply.listData[idx]["키"]);
					$.mobile.changePage("nice_shot.html","slide",true);
				});
				
				//페이스북 공유하기
				this.objCourse.$getViewLayer().find("li.bt_side>div div:eq(1) a, button").click(function(){
				    // TODO
					alert("페이스북");
					console.log("test :: " + document.location.href);
					
					var info = thisClass.objComm.getCourseTargetData();
                    
                    var b = "";
                    var $b = thisClass.objCourse.$getViewLayer().find("li p img").each(function(){
                        console.log("test :: " + $(this).attr("src"));
                        b += "<img src='" + $(this).attr("src") + "' />";
                    });
                     
                    var t = info["제목"];   
                    var d = thisClass.objCourse.$getViewLayer().find("div.view_detail").text();
                    var r = document.location.href;
                    console.log(d);
                    // _util.facebook_sharer(t, d, b, r);
					
					
					
				});
				
				//뒤로가기 이벤트
				$("section#course_view div.top_title_G div.top_left a").click(function(){
					$.mobile.changePage(thisClass.rtn_addr ,"slide", true)
				});
			}
			, _role: function(){
				if(!_util.getLogin("로그인")){
					//alert("로그인 후 이용하실 수 있습니다.");		    			
					this.goNavi("../course/course_view.html");		
					return false;
				}else{
					return true;
				}
	   	}
			, goNavi: function(rPage){			
				_gf.LOGIN_DATA.loginAfterUrl = rPage;
				$.mobile.changePage("../member/login.html","slide",true);
			}
			, spinStart: function(){
				$.mobile.showPageLoadingMsg();
			}
			, spinEnd: function(){
				$.mobile.hidePageLoadingMsg();
			}
			
	}
	
	//데이터연동		
	function CourseView_Comm(){
		this.courseTargetObj = null;		
		this.courseReplyList = null;
		this.courseRequest = null;
		
		this._init();		
	}
	CourseView_Comm.prototype = {
		_init: function(){
			this.courseRequest = {
				"아이디": _util.getLogin("아이디")
				, "나이스샷": null
				, "게시판키": null
				, "댓글내용": null
				, "댓글키": null
			}
		}
		/*-------------------------- 코스 상세 --------------------------*/
		, getCourseTarget: function(){
			var thisClass = this;
			var objJson = new MJson();
			var cm = new ConnectionManager();

			objJson.putPub(MJson.PUB.SID, "KB001");
			objJson.putPub(MJson.PUB.SERVICENAME, "getDetailKnowhowBoard");
			
			objJson.putParameter("board_seq", this.courseRequest["게시판키"]);
			objJson.putParameter("modpage_yn", "N");

			
			thisClass.courseTargetObj = "";

			cm.requestGet(objJson.getJsonString(), function($jsonData){
				
				var res = $jsonData["msp"]["contents"]["items"];
				if(res){

					var obj = res;
					thisClass.courseTargetObj = {
						"키": _util.nvl(obj.board__seq)
						, "골프클럽": _util.nvl(obj.golfclub__name)
						, "코스정보": _util.nvl(obj.course__info__name)
						, "홀정보": _util.nvl(obj.hole__no)
						, "제목": _util.nvl(obj.title)
						, "내용": _util.nvl(obj.content)
						, "닉네임": _util.nvl(obj.reg__nickname)
						, "나이스샷수": _util.nvl(obj.niceshot)
						, "댓글수": _util.nvl(obj.cr__cnt)
						, "등록자": _util.nvl(obj.reg__id)
						, "등록일자": _util.nvl(obj.reg__date)
						, "등록시간": _util.nvl(obj.reg__time)
						, "이미지": _util.nvl(obj.user__image)
						, "직접입력": _util.nvl(obj.userWriteYn)
						, "골프데이터": _util.nvl(obj.golfclub__data)
						, "코스데이터": _util.nvl(obj.course__data)
						, "홀데이터": _util.nvl(obj.hole__data)
					}
				}
				$(thisClass).trigger("evtFinishCourseView");
			}, function($err) {
				alert($err);
			});
		}
		/*-------------------------- 댓글 리스트 --------------------------*/
		, getReplyList: function(){
			var thisClass = this;
			var objJson = new MJson();
			var cm = new ConnectionManager();

			objJson.putPub(MJson.PUB.SID, "KB001");
			objJson.putPub(MJson.PUB.SERVICENAME, "getKnowhowCommentList");
			objJson.putPub(MJson.PUB.LISTCOUNT, "999");
			objJson.putPub(MJson.PUB.CURRPAGENO, "1");
			
			objJson.putParameter("board_seq", this.courseRequest["게시판키"]);

			cm.requestGet(objJson.getJsonString(), function($jsonData){
				
				var res = $jsonData["msp"]["contents"]["items"];
				thisClass.courseReplyList = [];
				if(res){
					if(!res.length){
						res = new Array(res);
					}
					for(var i=0;i<res.length;++i){
						var obj = res;
						thisClass.courseReplyList.push({
							"키": _util.nvl(obj[i].reply__seq)
							, "게시판키": _util.nvl(obj[i].board__seq)
							, "내용": _util.nvl(obj[i].content)
							, "등록자": _util.nvl(obj[i].reg__id)
							, "등록일자": _util.nvl(obj[i].reg__date)
							, "등록시간": _util.nvl(obj[i].reg__time)
							, "사용자ID": _util.nvl(obj[i].reg__id)
							, "이미지": _util.nvl(obj[i].user__image)
							, "닉네임": _util.nvl(obj[i].reg__nickname)
							, "나이스샷": _util.nvl(obj[i].niceshot, '0')
						});
					}
					
				}
				$(thisClass).trigger("evtFinishReplyList");
			}, function($err) {
				alert($err);
			});
		}
		/*-------------------------- 댓글 등록 --------------------------*/
		, registReply: function(){
			var thisClass = this;
			var objJson = new MJson();
			var cm = new ConnectionManager();
			
			objJson.putClient("userid", this.courseRequest["아이디"]);
			objJson.putPub("sid", "KB001");
			objJson.putPub("servicename", "regKnowhowComment");
			
			objJson.putParameter("board_seq", this.courseRequest["게시판키"]);
			objJson.putParameter("content", this.courseRequest["댓글내용"]);
			
			
			cm.requestGet(objJson.getJsonString(), function(ret){
				var resData = {
					"응답코드": (ret["msp"]["contents"]["serviceResult"]=="00000"?true:false)
					, "메세지": _util.getResultMsg(ret)
				}
				
				$(thisClass).trigger("evtFinishInsertCourseReply", resData);
			}, function($err) {
				alert($err);
			});
		}
		/*-------------------------- 댓글 삭제 --------------------------*/
		, deleteReply: function(){
			var thisClass = this;
			var objJson = new MJson();
			var cm = new ConnectionManager();
			
			//objJson.putClient("userid", "golfin3");
			objJson.putPub("sid", "KB001");
			objJson.putPub("servicename", "deleteKnowhowComment");
			
			objJson.putParameter("board_seq", this.courseRequest["게시판키"]);
			objJson.putParameter("reply_seq", this.courseRequest["댓글키"]);
			
			cm.requestGet(objJson.getJsonString(), function(ret){
				var resData = {
					"응답코드": (ret["msp"]["contents"]["serviceResult"]=="00000"?true:false)
					, "메세지": _util.getResultMsg(ret)
				}
				
				$(thisClass).trigger("evtFinishInsertCourseReply", resData);
			}, function($err) {
				alert($err);
			});
			
		}
		/*-------------------------- 게시글 삭제 --------------------------*/
		, deleteCourse: function(){
			var thisClass = this;
			var objJson = new MJson();
			var cm = new ConnectionManager();
			
			//objJson.putClient("userid", "golfin3");
			objJson.putPub("sid", "KB001");
			objJson.putPub("servicename", "deleteKnowhowBoard");
			
			objJson.putParameter("board_seq", this.courseRequest["게시판키"]);
			
			cm.requestGet(objJson.getJsonString(), function(ret){
				var resData = {
					"응답코드": (ret["msp"]["contents"]["serviceResult"]=="00000"?true:false)
					, "메세지": _util.getResultMsg(ret)
				}
				
				$(thisClass).trigger("evtFinishDeleteCourseView", resData);
			}, function($err) {
				alert($err);
			});
		}
		/*-------------------------- 나이스샷 --------------------------*/
		, registNiceShot: function(gubun){
			var thisClass = this;
			var objJson = new MJson();
			var cm = new ConnectionManager();
			var rtnView = "";
			
			objJson.putClient("userid", this.courseRequest["아이디"]);
			objJson.putPub("sid", "KB001");
			objJson.putPub("servicename", "updateNiceshot");
			
			objJson.putParameter("board_seq", this.courseRequest["게시판키"]);
			
			if(gubun == "view"){
				rtnView = "evtFinishUpdateNiceShot";
			}else{
				rtnView = "evtFinishInsertCourseReply";
			}
			
			if(this.courseRequest["댓글키"]){
				objJson.putParameter("reply_seq", this.courseRequest["댓글키"]);
			}
			
			cm.requestGet(objJson.getJsonString(), function(ret){
				var resData = {
					"응답코드": (ret["msp"]["contents"]["serviceResult"]=="00000"?true:false)
					, "메세지": _util.getResultMsg(ret)
				}
				
				$(thisClass).trigger(rtnView, resData);
			}, function($err) {
				alert($err);
			});
			
		}
		
		, getCourseTargetData: function(){
			return this.courseTargetObj;
		}
		, getCourseReplyList: function(){
			return this.courseReplyList;
		}
		, setCourseRequest: function(key,val){
			this.courseRequest[key]=val;
		}
		, getCourseRequest: function(key){
			return this.courseRequest[key];
		}
	}
	
	/*코스 상세 VIEW*/
	function clsCourseView(){
		this.listData = null;
		this._HTMLDom = null;
		this.userId = null;
		this._init();
	}
	
	clsCourseView.prototype = {
		_init: function(){
			var $layer = $("section#course_view>section>ul");
			this._HTMLDom = {
				"$layer": $layer
			}

		}
		, setDetail: function(thisData){
			
			this.display(thisData);
			
		}
		, display: function(thisData){
			var $layer = this._HTMLDom["$layer"];
//			var content = thisData["내용"];
//			var srtIdx = content.indexOf("<p>");
//			var endIdx = content.indexOf("</p>");
//			var img = "";
//			if(endIdx > 0){
//				img = content.substring(srtIdx, endIdx+4);
//				content = content.substring(endIdx+4, content.length);
//				
//				alert(img);
//				alert(content);
//			}
			
			if(thisData["직접입력"] == "Y"){
				$layer.find("li:eq(0) h5").html(thisData["골프데이터"] + "&nbsp;" + thisData["코스데이터"] + "&nbsp;" + thisData["홀데이터"] + "H");
			}else{
				$layer.find("li:eq(0) h5").html(thisData["골프클럽"] + "&nbsp;" + thisData["코스정보"] + "&nbsp;" + thisData["홀정보"] + "H");
			}
			$layer.find("li:eq(0) div").html(thisData["제목"]);
			$layer.find("li:eq(0) .nick").html(thisData["닉네임"]);
			$layer.find("li:eq(0) time").html(_util.fDateYmd(thisData["등록일자"]) + "&nbsp;" + _util.fTime(thisData["등록시간"]));
			//$layer.find("li:eq(2) span img").attr("src", _util.nvl(thisData["이미지"]).replace('/data/msp300/dl/files/free', 'http://192.168.0.82'));
			$layer.find("li:eq(2)").html(thisData["내용"]);
			$layer.find("li:eq(3)>div div:eq(0) .bt_nice_l span span").html(thisData["나이스샷수"]);
			if(this.userId == thisData["등록자"]){
				$layer.find("li:eq(1)").show();
			}else{
				$layer.find("li:eq(1)").hide();
			}
		}
		, $getViewLayer: function(){
			return this._HTMLDom["$layer"];
		}
		, setUserId: function(user_id){
			this.userId = user_id;
		}
	}
	
	/*댓글 리스트 VIEW*/
	function clsCourseViewReply(){
		this.listData = null;
		this._HTMLDom = null;
		this.userId = null;
		this._init();
	}
	
	clsCourseViewReply.prototype = {
		_init: function(){
			var $layer = $("section#course_view>section div.reply_area");
			this._HTMLDom = {
				"$layer": $layer
				, "$element": $layer.find("ul>li:first")
			}

			$layer.find(">ul").empty();
		}
			
		, setList: function(thisData){
			this.listData = thisData;	
			this.display(thisData);			
		}
		, display: function(thisData){
			var $layer = this._HTMLDom["$layer"];
			var $element = this._HTMLDom["$element"];
			var thisClass = this;
			
			$layer.find("h5 mark").html("(" + this.listData.length + ")");
			
			$layer.find("ul").empty();
			
			for(var i=0;i<this.listData.length;++i){
				$layer.find(">ul").append($element.clone(true));
			}
			
			$layer.find(">ul li").each(function(n){
				$(this).find("img").attr("src", _util.nvl(thisClass.listData[n]["이미지"]).replace('/data/msp300/dl/files/free', 'http://192.168.0.82'));
				$(this).find("h3").html(thisClass.listData[n]["닉네임"]);
				$(this).find("p:eq(0)").html(thisClass.listData[n]["내용"]);
				$(this).find("p:eq(1) mark").html("("+thisClass.listData[n]["나이스샷"]+")");
				$(this).find("time").html(_util.fDateYmd(thisClass.listData[n]["등록일자"]) + "&nbsp;" + _util.fTime(thisClass.listData[n]["등록시간"]));
				if(thisClass.listData[n]["등록자"] == thisClass.userId){
					$(this).find("span.ico_navi").show();
				}else{
					$(this).find("span.ico_navi").hide();
				}
			});
			
		}
		, $replyRegist: function(){
			return this._HTMLDom["$layer"].find("form");
		}
		, $getReplyLayer: function(){
			return this._HTMLDom["$layer"].find("ul");
		}
		, setUserId: function(user_id){
			this.userId = user_id;
		}
	}

//	$(document).bind("pageinit", function(event){
//		//alert("pageinit");
//		
//		var path = String(document.location);
//		if(path.indexOf("navi.html") == -1){
//			document.objControl = new CourseView();
//			document.objControl.onPageShow();	
//		}
//	});
